package {
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.net.URLLoaderDataFormat;
	import flash.utils.ByteArray;
	
	import manager.net.HTTPLoader;
	import manager.webservice.IWebServices;
	import manager.webservice.WebServiceControl;
	
	import org.adobe.basecode.Base64;
	import org.adobe.json.JSON;

	public class AppSWC extends Sprite implements IWebServices{
		private var bytes:ByteArray;
		private var http:HTTPLoader;
		private var web:WebServiceControl;
		private const URL:String = "http://192.168.0.10:8005/Phone.asmx";
		
		public function AppSWC() {
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			webHandler();
		}
		private function httpHandler():void{
			http = new HTTPLoader(completeHandler,errorHandler);
			http.dataFormat = URLLoaderDataFormat.BINARY;
			http.load("http://s1.hao123img.com/index/images/logo.png");
		}
		private function completeHandler(obj:Object):void{
			for(var item:String in obj){
				trace(item)
			}
			var bytes:ByteArray = new ByteArray();
			bytes.writeBytes(obj.resultData);
			bytes.position = 0;
			
			var loader:Loader = new Loader();
			loader.loadBytes(bytes);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE,handler1);
			
			http.destroy();
		}
		private function handler1(e:Event):void{
			this.addChild(e.target.content)
		}
		private function errorHandler(obj:Object):void{
			for(var item:String in obj){
				trace(item + ":" + obj[item])
			}
		}
		private function webHandler():void{
			bytes = new ByteArray;
			web = WebServiceControl.getInstance();
			web.addArgumentWebServices(this,"gc",["uidstr","1"],URL,handler);
		}
		private function handler(val:XML):void{
			var str:String = val.toString();
			var tmpArr:Array = org.adobe.json.JSON.decode(str);
			for(var i:int=0; i<tmpArr.length; i++){
				for(var key:String in tmpArr[i]){
					trace("属性:" + key + ";值:" + tmpArr[i][key])
				}
			}
		}
		public function updateData(val:*):void{
		}
	}
}